<?

require_once("cms/core/action/AbstractListAction.php");
require_once("cms/forum/om/TopicPeer.php");

class ListAction extends AbstractListAction {

    private $log;

    public function __construct() {
        $this->log =& LoggerManager::getLogger("ListAction");
    }

    public function activate(ActionConfig &$mapping, &$form, Request &$request, Response &$response) {

        $this->log->debug("Activating topics");
        $c = new Criteria();
        $c->add(TopicPeer::TOPIC_ID, $form->getItems(), Criteria::IN);
        $c->add(TopicPeer::ACTIVE, true);
        try {
            TopicPeer::doUpdate($c);
            $this->messages->add(ActionMessage::GLOBAL_MESSAGE,
                new ActionMessage("list.success.activate", true));
        } catch(PropelException $e) {
            $this->errors->add(ActionMessage::GLOBAL_MESSAGE,
                new ActionMessage("list.error.activate", true));
            $this->log->error($e->getMessage());
        }

    }

    public function deactivate(ActionConfig &$mapping, &$form, Request &$request, Response &$response) {

        $this->log->debug("Deactivating topics");
        $c = new Criteria();
        $c->add(TopicPeer::TOPIC_ID, $form->getItems(), Criteria::IN);
        $c->add(TopicPeer::ACTIVE, false);
        try {
            TopicPeer::doUpdate($c);
            $this->messages->add(ActionMessage::GLOBAL_MESSAGE,
                new ActionMessage("list.success.deactivate", true));
        } catch(PropelException $e) {
            $this->errors->add(ActionMessage::GLOBAL_MESSAGE,
                new ActionMessage("list.error.deactivate", true));
            $this->log->error($e->getMessage());
        }

    }

    public function close(ActionConfig &$mapping, &$form, Request &$request, Response &$response) {

        $this->log->debug("Closing topics");
        $c = new Criteria();
        $c->add(TopicPeer::TOPIC_ID, $form->getItems(), Criteria::IN);
        $c->add(TopicPeer::CLOSED, true);
        try {
            TopicPeer::doUpdate($c);
            $this->messages->add(ActionMessage::GLOBAL_MESSAGE,
                new ActionMessage("list.success.close", true));
        } catch(PropelException $e) {
            $this->errors->add(ActionMessage::GLOBAL_MESSAGE,
                new ActionMessage("list.error.close", true));
            $this->log->error($e->getMessage());
        }

    }

    public function open(ActionConfig &$mapping, &$form, Request &$request, Response &$response) {

        $this->log->debug("Opening topics");
        $c = new Criteria();
        $c->add(TopicPeer::TOPIC_ID, $form->getItems(), Criteria::IN);
        $c->add(TopicPeer::CLOSED, false);
        try {
            TopicPeer::doUpdate($c);
            $this->messages->add(ActionMessage::GLOBAL_MESSAGE,
                new ActionMessage("list.success.open", true));
        } catch(PropelException $e) {
            $this->errors->add(ActionMessage::GLOBAL_MESSAGE,
                new ActionMessage("list.error.open", true));
            $this->log->error($e->getMessage());
        }

    }

    public function delete(ActionConfig &$mapping, &$form, Request &$request, Response &$response) {

        $this->log->debug("Deleting topics");
        $c = new Criteria();
        $c->add(TopicPeer::TOPIC_ID, $form->getItems(), Criteria::IN);

        $conn = Propel::getConnection();

        try {

            $conn->begin();

            $c = new Criteria();
            $c->add(TopicPeer::TOPIC_ID, $form->getItems(), Criteria::IN);

            TopicPeer::doDelete($c, $conn);

            $conn->commit();

            $this->messages->add(ActionMessage::GLOBAL_MESSAGE,
                new ActionMessage("list.success.delete", true));

        } catch(PropelException $e) {
            $conn->rollback();
            $this->errors->add(ActionMessage::GLOBAL_MESSAGE,
                new ActionMessage("list.error.delete", true));
            $this->log->error($e->getMessage());
        }

    }


}
?>